package com.example.task1.ui.AllService.subway;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.task1.R;
import com.example.task1.bean.SubwayLostAndFoundBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class SubwayLostAndFoundAdapter extends BaseAdapter<SubwayLostAndFoundBean.DataDTO> {

    private Context context;
    private List<SubwayLostAndFoundBean.DataDTO> mData = new ArrayList<>();
    private TextView tvTime;
    private RecyclerView rvList;

    public SubwayLostAndFoundAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<SubwayLostAndFoundBean.DataDTO> rows) {
        int size = mData.size();
        mData.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.subwaylostandfountlist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<SubwayLostAndFoundBean.DataDTO> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, SubwayLostAndFoundBean.DataDTO date) {
        tvTime.setText(date.getPublishDate());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        SubwayLostAndFoundDetailAdapter subwayLostAndFoundDetailAdapter = new SubwayLostAndFoundDetailAdapter(context);
        rvList.setAdapter(subwayLostAndFoundDetailAdapter);
        rvList.setLayoutManager(linearLayoutManager);
        subwayLostAndFoundDetailAdapter.setData(date.getMetroFoundList());
    }

    @Override
    protected void holder(View view) {
        initView(view);
    }

    private void initView(View view) {
        tvTime = view.findViewById(R.id.tv_time);
        rvList = view.findViewById(R.id.rv_list);
    }
}
